#pragma once
#include "nocopy.h"
#include <functional>
#include <thread>
#include <memory>
#include <unistd.h>
#include <string>
#include <atomic>
#include "CurrentThread.h"

// #pragma once

// #include "nocopy.h"

// #include <functional>
// #include <thread>
// #include <memory>
// #include <unistd.h>
// #include <string>
// #include <atomic>
class Thread : nocopyable
{

public:
    using ThreadFunc = std::function<void()>;
    explicit Thread(ThreadFunc, const std::string &name = std::string());
    ~Thread();
    void start();
    void join();
    pid_t tid() const { return tid_; }
    bool started() const { return started_; }
    const std::string &name() const { return name_; }
    static int numCreated() { return numCreated_; }
private:
    void setDefaultName();
    bool started_;
    bool joined_;
    std::shared_ptr<std::thread> thread_;
    pid_t tid_;
    ThreadFunc func_;
    std::string name_;
    static std::atomic<int32_t> numCreated_;
};